package com.iversonx.adapter.example_1.service.v0;

import com.iversonx.adapter.example_1.domain.LogModel;
import com.iversonx.adapter.example_1.remote.file.LogFileOperateApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 *
 **/
@Service
public class LogServiceV0 {
    private final static Logger LOGGER = LoggerFactory.getLogger(LogServiceV0.class);
    @Autowired
    private LogFileOperateApi logFileOperate;
    
    /**
     * 保存日志
     */
    public void saveLog() {
        LogModel m = new LogModel();
        String uuid = UUID.randomUUID().toString();
        m.setLogId(uuid);
        m.setOperateTime("2019-10-14 00:12:45");
        m.setOperateUser("admin");
        Map<String, LogModel> map = new HashMap<>();
        map.put(m.getLogId(), m);
        logFileOperate.writeLog(map);
        LOGGER.info("日志写入： {}", m);
    }
    
    /**
     * 读取日志内容
     */
    public void readLog() {
        Map<String, LogModel> logs = logFileOperate.readLog();
        LOGGER.info("日志读取: {}", logs);
    }
}
